package club.xyes.zkh.ecommerce.commons.entity;

import club.xyes.zkh.ecommerce.commons.context.ApplicationConstants;
import club.xyes.zkh.ecommerce.commons.util.DateTimeUtil;
import lombok.Data;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import java.util.Date;

/**
 * Create by 郭文梁 2019/4/15 0015 11:53
 * BaseEntity
 * 实体类基类 提供公有属性和公有方法
 *
 * @author 郭文梁
 * @data 2019/4/15 0015
 */
@Data
public abstract class BaseEntity {
    /**
     * ID
     */
    @Id
    @GeneratedValue(generator = ApplicationConstants.Database.GENERATOR_JDBC)
    @Column(name = "id", nullable = false)
    private Integer id;
    /**
     * 创建时间
     */
    @Column(name = "create_time")
    private Date createTime;
    /**
     * 修改时间
     */
    @Column(name = "update_time")
    private Date updateTime;

    /**
     * 初始化BaseEntity中的属性
     */
    public void init() {
        updateTime = createTime = DateTimeUtil.now();
    }

    /**
     * 刷新更新时间
     */
    public void touch() {
        updateTime = DateTimeUtil.now();
    }
}
